<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
	<title>统计任务详情</title>
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css">
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/fontawesome-free-5.15.4-web/css/all.min.css" >
	<link rel="stylesheet" type="text/css" href="/static/m.css?v=041105" >
	<script src="/static/basic/plugins/jquery-3.4.1/jquery-3.4.1.min.js"></script>
	<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
	<script src="/static/init.js?v=0327111"></script>
	<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script src="/static/plugins/crypto-js.min.js"></script>
	<link rel="stylesheet" href="/static/sys/main/main.css?v=0327" >
	<!-- <script src="/static/basic/sea.js"></script> -->
	<!-- <script src="/static/basic/sea-config.js"></script> -->
	<!-- <script>
	seajs.use("sys/main/main.js?r="+Math.random());
	</script> -->
	<link rel="stylesheet" href="/view/sys/main/layui.css?v=0326">
	<style>
		.icon{
			display:none;
		}
		.mpanelbody{
			overflow-y:auto;
			min-height:50px;
			max-height:150px;
		}
	</style>
</head>
<body class="easyui-layout" data-options="fit:true" style="width:100%;height:100%;overflow-y:hidden;" >
<div id="window-mmask" class="window-mmask" ><div class="window-mmask-msg" >页面加载中,请稍候...</div></div>
<!-- <div data-options="region:'north',border:false,split:false" class="header">
    <span style="float:right; padding-right:20px;" class="head">欢迎 <span id="nickname"></span> <a href="javascript:void(0)" id="editpass">修改密码</a> <a href="javascript:void(0)" id="loginOut">安全退出</a></span>
    <span style="padding-left:10px;">
    <img src="/static/sys/main/images/logo32x32.png" align="absmiddle" /></span>
</div> -->

<div data-options="region:'west',split:false,title:'统计明细表'" style="" class="side" id="west">
	<div id="tt"></div>
</div>
<div data-options="region:'center'" id="mainPanle" style="overflow-y:hidden">
	<iframe id="gridFrame" scrolling="no" frameborder="0"  src="" style="width:100%;height:100%;"></iframe>
</div>

<script>
	var taskId=$.query.get("taskId");
	$(function(){
		$.extend($.fn.tree.methods,{
			unselect:function(jq){//取消选择
				return jq.each(function(){
					$(this).find("div.tree-node-selected").removeClass("tree-node-selected");
				});
			}
		});

		let treeData=[];
		//查询所有统计表
		$.ajax({
			type: "post",
			contentType:"application/json",
			async:false,
			url:"/simple/namedList/select_ec_config_detail_by_taskId",
			data:JSON.stringify({taskId:taskId}),
			success:function(result){
				if(result.success){
					$.each(result.data,function(i,v){
						treeData.push({"id":v.id,"text":v.shortName,"attributes":{"statType":v.statType,"tableName":v.tableName}});
					});

				}else{
					$.messager.alert("提示", "查询配置信息失败！<br>"+result.message);
				}
			}
		})

		$('#tt').tree({
			data: treeData,
			onClick:openGrid
		});


	});

	function openGrid(node){
		//console.log(node);
		let statType=node.attributes.statType;
		if(statType=="output"){
			$("#gridFrame").attr("src","/compore/stat_result.html?reportName="+encodeURIComponent(node.text)+"&reportId="+node.id+"&tableName="+node.attributes.tableName+"&taskId="+taskId)
		}else{
			$("#gridFrame").attr("src","/compore/stat_data.html?reportName="+encodeURIComponent(node.text)+"&reportId="+node.id+"&tableName="+node.attributes.tableName+"&taskId="+taskId)

		}

	}
	var _menus = {};

	function stringToHex(str){
		var val = "";
		for (var i = 0; i < str.length; i++) {
			val += str.charCodeAt(i).toString(16);
		}
		return val;
	}


	var onlyOpenTitle="首页";//不允许关闭的标签的标题

	function init(){
		$.ajax({
			type: "post",
			url: "/authenticated/menu/query",
			data:JSON.stringify({}),
			dataType:"json",
			contentType:"application/json",
			success: function(result){
				if(result.success){
					_menus=toTreeData(result.data,"id","parentId");
					//InitLeftMenu();
				}else{
					$.messager.alert("提示", "初始化菜单失败！");
				}
			}
		});
	}



	//初始化左侧
	var menu={selected:null};
	function InitLeftMenu() {
		//console.log(_menus);
		var menulist ='<div class="side-scroll"><div id="menu" style="width:200px;" class="easyui-accordion " data-options="multiple:true" >';
		$.each(_menus, function(i, n) {
			var isSelected = i == 0 ? true : false;
			var isLeaf=(n.children&&n.children.length>0)?false:true;//是否是叶子节点
			var isCollapsed=isLeaf?false:true;//面板是否折叠的。
			var isCollapsible=isLeaf?false:true;//是否显示折叠按钮
			var title=isLeaf?'':n.text;
			var bodyCls=isLeaf?'m-accordion-header side-overflow-hidden':'side-overflow-hidden';
			var iconCls=n.iconCls?n.iconCls:'';
			menulist +=`<div data-id="${n.id}" data-options="iconCls:'${iconCls}',collapsed:${isCollapsed},collapsible:${isCollapsible},title:'${title}',bodyCls:'${bodyCls}'" >`;
			var data='';
			if(isLeaf){//
				data=`[_menus[${i}]]`;
			}else{
				data=`_menus[${i}].children`;
			}
			menulist +=`<ul id="tree-${n.id}" class="easyui-tree" data-options="data:${data},animate:true,onClick:onMenuClick"></ul>`;
			menulist+='</div>';
		});
		menulist+='</div></div>';
		$("#west").html(menulist);
		$.parser.parse('#west');


		var t=$('#tree-'+$('#menu').accordion('panels')[0].data("id"));
		//t.tree('isLeaf',t.tree('getRoot'));
		var root=t.tree('getRoot')
		//console.log("根节点",root);
		//console.log("根节点是否叶子节点",t.tree('isLeaf',root.target));
		//var child=t.tree('getChildren',root.target);
		//console.log(child);

		//addTab(node.text,node.path);
		//$('#menu').accordion('select',0);
	}
	function onMenuClick(node) {
		var t=$(this);
		if(t.tree('isLeaf',node.target)){//叶子节点
			//console.log(node);

			if (node.path) {
				if(node.path.startsWith("js:")){
					let fun=node.path.substring(3);
					eval(fun);
				}else{
					addTab(node.text,node.path);
				}
			}else{
				//alert('菜单没有初始化链接');
			}
			//当前选中菜单
			if(menu.selected){//当前有选中
				if(menu.selected.is(t)){

				}else{
					menu.selected.tree('unselect');
					menu.selected=t;
				}
			}else{
				menu.selected=t;
			}
		}else{
			//console.log(node);
			if (node.state == "closed") {
				t.tree('expand', node.target);
			} else if (node.state == 'open') {
				t.tree('collapse', node.target);
			}
		}

	}


	function find(menuid){
		var obj=null;
		$.each(_menus, function(i, n) {
			$.each(n.children, function(j, o) {
				if(o.id==menuid){
					obj = o;
				}
			});
		});
		return obj;
	}

	function addTab(subtitle,url,this_){
		if(this_){
			$(".menu_selected").removeClass("menu_selected");
			$(this_).parent().addClass("menu_selected");
		}
		if(!$('#tabs').tabs('exists',subtitle)){
			$('#tabs').tabs('add',{
				fit:true,
				title:subtitle,
				content:createFrame(url),
				closable:subtitle!="首页"
			});
		}else{
			$('#tabs').tabs('select',subtitle);
			$('#mm-tabupdate').click();
		}
		tabClose();
	}

	function createFrame(url)
	{
		var s = '<iframe scrolling="no" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
		return s;
	}

	function tabClose()
	{
		/*双击关闭TAB选项卡*/
		$(".tabs-inner").dblclick(function(){
			var subtitle = $(this).children(".tabs-closable").text();
			$('#tabs').tabs('close',subtitle);
		})
		/*为选项卡绑定右键*/
		$(".tabs-inner").bind('contextmenu',function(e){
			$('#mm').menu('show', {
				left: e.pageX,
				top: e.pageY
			});

			var subtitle =$(this).children(".tabs-closable").text();

			$('#mm').data("currtab",subtitle);
			$('#tabs').tabs('select',subtitle);
			return false;
		});
	}


	//绑定右键菜单事件
	function tabCloseEven() {

		$('#mm').menu({
			onClick: function (item) {
				closeTab(item.id);
			}
		});

		return false;
	}

	function closeTab(action)
	{
		var alltabs = $('#tabs').tabs('tabs');
		var currentTab =$('#tabs').tabs('getSelected');
		var allTabtitle = [];
		$.each(alltabs,function(i,n){
			allTabtitle.push($(n).panel('options').title);
		})


		switch (action) {
			case "refresh":
				var iframe = $(currentTab.panel('options').content);
				var src = iframe.attr('src');
				$('#tabs').tabs('update', {
					tab: currentTab,
					options: {
						content: createFrame(src)
					}
				})
				break;
			case "close":
				var currtab_title = currentTab.panel('options').title;
				if(currtab_title=='首页'){
					//$.messager.alert("提示", "首页不允许关闭！");
					return false;
				}
				$('#tabs').tabs('close', currtab_title);
				break;
			case "closeall":
				$.each(allTabtitle, function (i, n) {
					if (n != onlyOpenTitle){
						$('#tabs').tabs('close', n);
					}
				});
				break;
			case "closeother":
				var currtab_title = currentTab.panel('options').title;
				$.each(allTabtitle, function (i, n) {
					if (n != currtab_title && n != onlyOpenTitle)
					{
						$('#tabs').tabs('close', n);
					}
				});
				break;
			case "closeright":
				var tabIndex = $('#tabs').tabs('getTabIndex', currentTab);

				if (tabIndex == alltabs.length - 1){
					$.messager.alert("提示", "没有可以关闭的标签页！");
					return false;
				}
				$.each(allTabtitle, function (i, n) {
					if (i > tabIndex) {
						if (n != onlyOpenTitle){
							$('#tabs').tabs('close', n);
						}
					}
				});

				break;
			case "closeleft":
				var tabIndex = $('#tabs').tabs('getTabIndex', currentTab);
				if (tabIndex == 1) {
					//$.messager.alert("提示", "首页不允许关闭！");
					return false;
				}
				$.each(allTabtitle, function (i, n) {
					if (i < tabIndex) {
						if (n != onlyOpenTitle){
							$('#tabs').tabs('close', n);
						}
					}
				});

				break;
			case "exit":
				$('#closeMenu').menu('hide');
				break;
		}
	}


	//弹出信息窗口 title:标题 msgString:提示信息 msgType:信息类型 [error,info,question,warning]
	function msgShow(title, msgString, msgType) {
		$.messager.alert(title, msgString, msgType);
	}
	/**
	 * 更换页面风格
	 * @param topjuiThemeName
	 */
	function changeTheme(themeName) {/* 更换主题 */
		var $dynamicTheme = $('#dynamicTheme');
		var themeHref = $dynamicTheme.attr('href');
		var themeHrefNew = themeHref.substring(0, themeHref.indexOf('themes')) + 'themes/default/topjui.' + themeName + '.css';
		// 更换主页面风格
		$dynamicTheme.attr('href', themeHrefNew);

		// 更换iframe页面风格
		var $iframe = $('iframe');
		if ($iframe.length > 0) {
			for (var i = 1; i < $iframe.length; i++) {
				var ifr = $iframe[i];
				var $iframeDynamicTheme = $(ifr).contents().find('#dynamicTheme');
				var iframeThemeHref = $iframeDynamicTheme.attr('href');
				var iframeThemeHrefNew = iframeThemeHref.substring(0, iframeThemeHref.indexOf('themes')) + 'themes/default/topjui.' + themeName + '.css';
				$iframeDynamicTheme.attr('href', iframeThemeHrefNew);
			}
		}

		$.cookie('topjuiThemeName', themeName, {
			expires: 7,
			path: '/'
		});
	};




</script>
</body>
</html>